# coding=utf-8
import requests
import xlwt


def test_data():
    try:
        url = "https://jinyiyun.com/amo/data/sale-getSaleList?confirmStatus=2&pageNum=1&pageSize=50"
        cookie = {
            'FINANCE-CARPORT-TOKEN': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsIm1vYmlsZSI6IjEzMDU4MDE5MzAyIiwiaWF0IjoxNTkyODMyNjYxLCJleHAiOjE1OTM0Mzc0NjF9.nPhK3ODXMozC83ZXeJRYbIE8Vr6TD_j4QoWghU05slQ'}

        r1 = requests.get(url, cookies=cookie, timeout=15)
        result = r1.json()['data']['pageData']
        print(result)
        workbook = xlwt.Workbook()
        sheet1 = workbook.add_sheet('data')
        ll = list(result[0].keys())
        for i in range(0, len(ll)):
            sheet1.write(0, i, ll[i])
        for j in range(0, len(result)):
            m = 0
            ls = list(result[j].values())
            for k in ls:
                sheet1.write(j + 1, m, k)
                m += 1
        workbook.save('cardata.xls')



    except Exception as ex:
        print(111)
        print(ex)


if __name__ == '__main__':
    test_data()
